app.controller 'ActivityListController', [
	'$scope', 'Activity', 'activityList', '$location'
	,($scope, Activity, activityList, $location)->
		$scope.activityList = activityList
		$scope.activityListClass = 'active'
		$scope.detailView = (activity)->
			$location.path '/activity/detail/'+ activity.id
]

app.controller 'ActivityDetailController', [
	'$scope', '$http', 'activity', '$timeout', '$alert', '$location'
	,($scope, $http, activity, $timeout, $alert, $location)->
		$scope.activityListClass = 'active'
		$scope.activity = activity
		$scope.submit = (sign, callback)->
			sign.activity_id = activity.id
			$http.post('/main/activity/'+activity.id+'/sign', sign).success ()->
				$alert({title:'报名成功,后面会有社工联系您',placement:'top', type:'info',show:true, duration:3})
				do callback
]

app.config ['$routeProvider', ($routeProvider)->
	$routeProvider.when '/activity/list',
		templateUrl: '/main/tmpl/activity_list'
		controller: 'ActivityListController'
		resolve:
			activityList: (Activity)->
				Activity.query()
 
	$routeProvider.when '/activity/detail/:id',
		templateUrl : '/main/tmpl/activity_detail'
		controller : 'ActivityDetailController'
		resolve : 
			activity: (Activity, $route)->
				Activity.get {id: $route.current.params.id}

	$routeProvider.when '/activity',
		redirectTo : '/activity/list'
]
